//javac -Xlint:unchecked Tree.java
    
    public class Tree<E> {
        E[] array;
    
        public Tree() {
    array = (E[]) new Object[16];
        }
    
        public boolean isEmpty() {
    return ( array[1] == null );
        }
    
        public int left( int i ) {
    return ( 2 * i );
        }
    
        public int right( int i ) {
    return ( (2 * i ) + 1 );
        }
    
        public int parent( int i ) {
    return ( i / 2 );
        }
    
        public E getElement( int i ) {
    if( i < 0 || i >= array.length )
        return ( null );
    return ( array[i] );
        }
    
        public void setElement( int i, E e ) {
    if( i < 0 || i >= array.length )
        return;
    array[i] = e;
        }
    
        public void printPreorder( int i ) {
    if( array[i] == null )
        return;
    System.out.println( array[i].toString() );
    printPreorder( left( i ) );
    printPreorder( right( i ) );
        }
    
        public void printInorder( int i ) {
    if( array[i] == null )
        return;
    printPreorder( left( i ) );
    System.out.println( array[i].toString() );
    printPreorder( right( i ) );
        }
    
        public static void main( String[] args ) {
    Tree t = new Tree();
    
    int root = 1;
    t.setElement( root, "Data for root" );
    t.setElement( t.left( root ), "Data for left" );
    t.setElement( t.right( root ), "Data for right" );
    
    System.out.println( "Preorder printing" );
    t.printPreorder( 1 );
    System.out.println();
    
    System.out.println( "Inorder printing" );
    t.printInorder( 1 );
    System.out.println();
        }
    }